/*
 * CAudioRender.h
 *
 *  Created on: 2016年3月18日
 *      Author: terry
 */

#ifndef CAUDIORENDER_H_
#define CAUDIORENDER_H_

#include "AudioRender.h"
#include "AudioDevice.h"
#include "SharedPtr.h"
#include "TCriticalSection.h"


namespace av
{

typedef std::shared_ptr< AudioDevice >	AudioDevicePtr;

class CAudioRender: public AudioRender
{
public:
	CAudioRender();
	virtual ~CAudioRender();

	virtual bool getTimePoint(int64_t& clock, int64_t& pts);

	virtual void close();

	virtual bool isOpen();

	virtual int play();
	virtual int pause();
	virtual void stop();

	virtual int getState();

	virtual void setFormat(const MediaFormat& fmt);

	virtual int write(AVFramePtr frame);

	virtual void flush();

	virtual void setScale(AVRational scale);

    virtual bool setProp(const std::string& name, const std::string& value);

	/**
	 * 打开音频播放设备
	 * @param sampleRate    采样率,取值有：8000,16000,32000
	 * @param channels      通道数， 取值[1,2]
	 * @param sampleFmt     采样格式
	 * @return
	 */
	virtual int open(int sampleRate, int channels, int sampleFmt);

	/**
	 * 获取音量
	 * @return
	 */
	virtual float getVolume();

	/**
	 * 设置音量
	 * @param vol   取值范围：[0.0,1.0]
	 * @return
	 */
	virtual int setVolume(float vol);

	virtual bool isMute();

	virtual int setMute(bool muted);

	virtual void dropTo(int64_t pts);


protected:
	void setState(StreamState state);

protected:
	AudioDevicePtr	m_device;
	StreamState	m_state;

	comn::CriticalSection	m_cs;



};



} /* namespace av */

#endif /* CAUDIORENDER_H_ */
